
package com.LinLight.app.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.RelativeLayout;

import com.LinLight.app.MyApplication;
import com.LinLight.app.R;


public class LeftFragment extends Fragment {
	
	private MyApplication application;
	private Activity mActivity = null;
	private List<Map<String, Object>> list = null;
	private List<Map<String, Object>> newList = null;
//	private AbPullListView mAbPullListView = null;
//	private int currentPage = 1;
//	private AbTaskQueue mAbTaskQueue = null;
//	private ArrayList<String> mPhotoList = new ArrayList<String>();
//	private ImageListAdapter myListViewAdapter = null;
	
	private RelativeLayout relayMainScene, relayLightList, relayMusic, relayShake; 

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) { 
		 mActivity = this.getActivity();
		 application = (MyApplication) mActivity.getApplication();
		 
//		 Button view = new Button(mActivity);
//		 view.setText("Fragment2");
//		 view.setTextColor(Color.RED);
		 
		 View view = inflater.inflate(R.layout.right_menu, null);
		 relayMainScene = (RelativeLayout) view.findViewById(R.id.main_page_scene);
		 relayMainScene.setVisibility(View.GONE);
		 relayLightList = (RelativeLayout) view.findViewById(R.id.main_page_light_list);
		 relayMusic = (RelativeLayout) view.findViewById(R.id.main_page_music);
		 relayShake = (RelativeLayout) view.findViewById(R.id.main_page_shake);
		 
		 relayMainScene.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				
			}
		});
		 
		 
		 relayLightList.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					
					mActivity.startActivity(new Intent(mActivity, LightListActivity.class));
				}
			});
		 
		 relayMusic.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					
					mActivity.startActivity(new Intent(mActivity, MusicActivity.class));
				}
			});
		 
		 relayShake.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					
					mActivity.startActivity(new Intent(mActivity, ShakeActivity.class));
				}
			});
		 
//		 mPhotoList.add("http://img01.taobaocdn.com/bao/uploaded/i3/13215035600700175/T1C2mzXthaXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");  
//		 mPhotoList.add("http://img01.taobaocdn.com/bao/uploaded/i2/13215025617307680/T1AQqAXqpeXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
//		 mPhotoList.add("http://img01.taobaocdn.com/bao/uploaded/i1/13215035569460099/T16GuzXs0cXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
//		 mPhotoList.add("http://img01.taobaocdn.com/bao/uploaded/i2/13215023694438773/T1lImmXElhXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
//		 mPhotoList.add("http://img01.taobaocdn.com/bao/uploaded/i3/13215023521330093/T1BWuzXrhcXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");  
//		 mPhotoList.add("http://img01.taobaocdn.com/bao/uploaded/i4/13215035563144015/T1Q.eyXsldXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");  
//		 mPhotoList.add("http://img01.taobaocdn.com/bao/uploaded/i3/13215023749568975/T1UKWCXvpXXXXXXXXX_!!0-item_pic.jpg_230x230.jpg"); 
//		 mAbTaskQueue = AbTaskQueue.getInstance();
//	     //获取ListView对象
//         mAbPullListView = (AbPullListView)view.findViewById(R.id.mListView);
//         //设置进度条的样式
//         mAbPullListView.getHeaderView().setHeaderProgressBarDrawable(this.getResources().getDrawable(R.drawable.progress_circular));
//         mAbPullListView.getFooterView().setFooterProgressBarDrawable(this.getResources().getDrawable(R.drawable.progress_circular));
//         //ListView数据
//    	 list = new ArrayList<Map<String, Object>>();
//    	
//    	 //使用自定义的Adapter
//    	 myListViewAdapter = new ImageListAdapter(mActivity, list,R.layout.list_items,
//				new String[] { "itemsIcon", "itemsTitle","itemsText" }, new int[] { R.id.itemsIcon,
//						R.id.itemsTitle,R.id.itemsText });
//    	 mAbPullListView.setAdapter(myListViewAdapter);
//    	 //item被点击事件
//    	 mAbPullListView.setOnItemClickListener(new OnItemClickListener(){
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view,
//					int position, long id) {
//			}
//    	 });

		 return view;
	} 
	
	

	@Override
	public void onStart() {
		super.onStart();
		//定义两种查询的事件
//    	final AbTaskItem item1 = new AbTaskItem();
//		item1.listener = new AbTaskListener() {
//
//			@Override
//			public void update() {
//				list.clear();
//				if(newList!=null && newList.size()>0){
//	                list.addAll(newList);
//	                myListViewAdapter.notifyDataSetChanged();
//	                newList.clear();
//   		    	}
//				mAbPullListView.stopRefresh();
//			}
//
//			@Override
//			public void get() {
//	   		    try {
//	   		    	Thread.sleep(1000);
//	   		    	currentPage = 1;
//	   		    	newList = new ArrayList<Map<String, Object>>();
//	   		    	Map<String, Object> map = null;
//	   		    	
//	   		    	for (int i = 0; i < 10; i++) {
//	   		    		map = new HashMap<String, Object>();
//	   					map.put("itemsIcon",mPhotoList.get(new Random().nextInt(mPhotoList.size())));
//		   		    	map.put("itemsTitle", "[Fragment2]"+i);
//		   		    	map.put("itemsText", "[Fragment2]..."+i);
//		   		    	newList.add(map);
//	   				}
//	   		    } catch (Exception e) {
//	   		    }
//		  };
//		};
		
//		final AbTaskItem item2 = new AbTaskItem();
//		item2.listener = new AbTaskListener() {
//
//			@Override
//			public void update() {
//				if(newList!=null && newList.size()>0){
//					list.addAll(newList);
//					myListViewAdapter.notifyDataSetChanged();
//					newList.clear();
//                }
//				mAbPullListView.stopLoadMore();
//			}
//
//			@Override
//			public void get() {
//	   		    try {
//	   		    	currentPage++;
//	   		    	Thread.sleep(1000);
//	   		    	newList = new ArrayList<Map<String, Object>>();
//                    Map<String, Object> map = null;
//	   		    	
//	   		    	for (int i = 0; i < 10; i++) {
//	   		    		map = new HashMap<String, Object>();
//	   					map.put("itemsIcon",mPhotoList.get(new Random().nextInt(mPhotoList.size())));
//		   		    	map.put("itemsTitle", "item上拉"+i);
//		   		    	map.put("itemsText", "item上拉..."+i);
//		   		    	newList.add(map);
//	   				}
//	   		    } catch (Exception e) {
//	   		    	currentPage--;
//	   		    	newList.clear();
//	   		    }
//		  };
//		};
		
//		mAbPullListView.setAbOnListViewListener(new AbOnListViewListener(){
//
//			@Override
//			public void onRefresh() {
//				mAbTaskQueue.execute(item1);
//			}
//
//			@Override
//			public void onLoadMore() {
//				mAbTaskQueue.execute(item2);
//			}
//			
//		});
		
    	//第一次下载数据
//		mAbTaskQueue.execute(item1);
	}



	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

}

